﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using mmoss.orm;
using mmoss.web;

public partial class Templates_POS : System.Web.UI.MasterPage
{
    private PageBase l_page = new PageBase();
    protected void Page_Load(object sender, EventArgs ea)
    {

        //handle patient permissions
        //lnkPOS.Visible = PageBase.LoginUser
        //handle events
        User l_user = l_page.LoginUser;
        lnkPatients.Visible = l_user.ValidatePerm(
        lnkPatients.Click += delegate(System.Object o, System.EventArgs e)
        { Response.Redirect("~/private/Patient/PatientAddEdit.aspx"); };

        lnkPOS.Click += delegate(System.Object o, System.EventArgs e)
        { Response.Redirect("~/private/pos/posHome.aspx"); };

        lnkInventory.Click += delegate(System.Object o, System.EventArgs e)
        { Response.Redirect("~/private/POS/Inventory.aspx"); };

        lnkReport.Click += delegate(System.Object o, System.EventArgs e)
        { Response.Redirect("~/private/Patient/PatientAddEdit.aspx"); };

        if (Request["__EVENTTARGET"] != null)
        {
            if (Request["__EVENTTARGET"].ToString() == "hotkey")
            {
                string sToGo = Request["__EVENTARGUMENT"].ToString();
                switch (sToGo)
                {
                    case "altn":
                        //add a new patient
                        Response.Redirect("~/Private/Patient/PatientAddEdit.aspx");
                        break;
                    case "altr":
                        //to register
                        Response.Redirect("~/Private/POS/POSHome.aspx");
                        break;
                }
            }
        }

    }
    [WebMethod]
    public static Int64 checkPatientDriversLicense(string sDriversNumber)
    {
        Patient l_returnPatient = dbconn.LinqContext.Patients.Get("",sDriversNumber,"",null,null);
        if (l_returnPatient != null)
        {
            return l_returnPatient.patientID;
            //do the redirect here probably
        }
        else
        {
            return -1;
        }
    }
}
